﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BAL.Entities;
using BAL.Utils;
using BAL.Components;
using DigitalAnts.MasterPage;
using System.Drawing;

namespace DigitalAnts.User
{
    public partial class EditPassword : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if(!IsPostBack)
            {
                ((UserLayout)Page.Master).ChangePassword = false;
                ((UserLayout)Page.Master).ChangePasswordColor = Color.Red;
                ((UserLayout)Page.Master).UnabelChangePasswordUnderline = false;
            }
        }

        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            UserEditPassword();
        }

        #region --- User modify their passwords
        private void UserEditPassword()
        {   
            // Create new instance of user object
            clsUser obj = new clsUser();
            obj.UserID = Convert.ToInt32(Session["UserID"]);

            /* Encrypt current password and */
            obj.Password = clsSecurity.doEncryptPasswordWithMD5(txtOldPassword.Text.Trim()); 
            obj.NewPassword = clsSecurity.doEncryptPasswordWithMD5(txtNewPassword.Text.Trim()); 

            // Do user login method
            if (clsUserBAL.doEditPassword(obj) == true) // Edit password success
            {
                Response.Redirect("~/User/EditPasswordSuccess.aspx");
            }
            else
            {

            }

        }
        #endregion ---
    }
}